<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/10/16
 * Time: 17:34
 */

namespace HiCommon\Model;

class DiscoverApprise extends Base
{
    
    protected $table = 'discover_apprise';
    
    protected $guarded = [];
    
    //public $timestamps = false;
    
    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [
    ];
    


    //管理前段用户表
    public function to_user()
    {
        return $this->belongsTo(Users::class, 'user_id')->select('id','nickname','head_img');
    }

    //点赞是统计
    public function zan()
    {
        return $this->hasMany(DiscoverZan::class, 'link_id')->where('type',1);
    }

    //用户是否点赞
    public function is_zan()
    {
        $user_id = small_api_user_id();
        return $this->hasMany(DiscoverZan::class, 'link_id')->where(['type'=>1,'user_id'=>$user_id]);
    }

    //关联朋友圈信息
    public function discover()
    {
        return $this->belongsTo(Discover::class, 'discover_id')->select('id','title','author_id','img','type','look_num');
    }

    //评论点赞是统计
    public function zan_comment()
    {
        return $this->hasMany(DiscoverZan::class, 'link_id')
            ->select('id','user_id','link_id')
            ->where('type',2);
    }









}